home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Grafik / Misc / StarGate / Developers / StarGateExample.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-02-01  |  8.0 KB  |  263 lines

  1. /* StarGateExample 2.0
  2.    (c) 1999-2000 by Felix Schwarz (felix@innovative-web.de).
  3.    All rights reserved.
  4.    This sourcecode is placed in the Public Domain:
  5.     Use it for whatever you want, but don`t make
  6.     me responsible, if anything doesn`t work as
  7.     it should. This sourcecode is supplied "as is"
  8.     and I cannot be held responsible, if it causes
  9.     any damages and/or errors, loss of money, health
  10.     or whatever. Use it fully at your own risk.
  11.  
  12.    The StarGate Plugin may be included into an archive
  13.    with previous permission by Felix Schwarz. Drop me
  14.    (felix@innovative-web.de) a mail and ask for a free
  15.    license.
  16. */
  17.  
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20.  
  21. #include <exec/ports.h>
  22. #include <clib/exec_protos.h>
  23. #include "stargate.h"
  24.  
  25. struct fsbitmap
  26. {
  27.         APTR location;   // Pointer to the RGB-data
  28.         long width;      // width of the image to transmit
  29.         long height;     // height of the image to transmit
  30.         long type;       // Set this to 3
  31. };
  32.  
  33. // Send an image to fxPAINT without saving it inbetween
  34. BOOL sendimg_to_stargate(struct fsbitmap *fsb)
  35. {
  36.         struct SGMessage msg;
  37.         struct Message *reply;
  38.         struct MsgPort *ReplyPort;
  39.         struct MsgPort *SGPort;
  40.         BOOL ok=FALSE;
  41.  
  42.         if (ReplyPort=CreateMsgPort())
  43.         {
  44.                 Forbid();
  45.                 if (SGPort=FindPort("Stargate Airport"))
  46.                 {
  47.                         msg.msg.mn_Node.ln_Type = NT_MESSAGE;
  48.                         msg.msg.mn_Length       = sizeof(struct SGMessage);
  49.                         msg.msg.mn_ReplyPort    = ReplyPort;
  50.                         msg.fsb                 = fsb;
  51.  
  52.                         PutMsg(SGPort, (struct Message *) &msg);
  53.                 }
  54.                 Permit();
  55.  
  56.                 if (SGPort)
  57.                 {
  58.                         Wait(1L << ReplyPort->mp_SigBit);
  59.                         reply=GetMsg(ReplyPort);
  60.                         ok=TRUE;
  61.                 }
  62.                 else
  63.                 {
  64.                         // Give out this (or similiar) error message here:
  65.                         // "Stargate not found or fxPAINT not started"
  66.                 }
  67.  
  68.                 DeleteMsgPort(ReplyPort);
  69.         }
  70.  
  71.         return(ok);
  72. }
  73.  
  74. // Send a filename to fxPAINT in order to fxPAINT loading that file
  75. BOOL sendfile_to_stargate (char *file)
  76. {
  77.         struct SGMessageExt msg;
  78.         struct Message *reply;
  79.         struct MsgPort *ReplyPort;
  80.         struct MsgPort *SGPort;
  81.         BOOL ok=FALSE;
  82.  
  83.         if (ReplyPort=CreateMsgPort())
  84.         {
  85.                 Forbid();
  86.                 if (SGPort=FindPort("Stargate Airport"))
  87.                 {
  88.                         msg.msg.mn_Node.ln_Type = NT_MESSAGE;
  89.                         msg.msg.mn_Length       = sizeof(struct SGMessageExt);
  90.                         msg.msg.mn_ReplyPort    = ReplyPort;
  91.                         msg.type                = SG_LOAD_IMAGE;
  92.                         msg.data                = (APTR) file;
  93.  
  94.                         PutMsg(SGPort, (struct Message *) &msg);
  95.                 }
  96.                 Permit();
  97.  
  98.                 if (SGPort)
  99.                 {
  100.                         Wait(1L << ReplyPort->mp_SigBit);
  101.                         reply=GetMsg(ReplyPort);
  102.                         ok=TRUE;
  103.                 }
  104.                 else
  105.                 {
  106.                         // Give out this (or similiar) error message here:
  107.                         // "Stargate not found or fxPAINT not started"
  108.                 }
  109.  
  110.                 DeleteMsgPort(ReplyPort);
  111.         }
  112.  
  113.         return(ok);
  114. }
  115.  
  116. // Get number of pictures in memory of fxPAINT
  117. long num_of_pics_in_stargate (void)
  118. {
  119.         struct SGMessageExt msg;
  120.         struct Message *reply;
  121.         struct MsgPort *ReplyPort;
  122.         struct MsgPort *SGPort;
  123.         long res=0;
  124.  
  125.         if (ReplyPort=CreateMsgPort())
  126.         {
  127.                 Forbid();
  128.                 if (SGPort=FindPort("Stargate Airport"))
  129.                 {
  130.                         msg.msg.mn_Node.ln_Type = NT_MESSAGE;
  131.                         msg.msg.mn_Length       = sizeof(struct SGMessageExt);
  132.                         msg.msg.mn_ReplyPort    = ReplyPort;
  133.                         msg.type                = SG_NUM_OF_IMGS;
  134.                         msg.data                = NULL;
  135.  
  136.                         PutMsg(SGPort, (struct Message *) &msg);
  137.                 }
  138.                 Permit();
  139.  
  140.                 if (SGPort)
  141.                 {
  142.                         Wait(1L << ReplyPort->mp_SigBit);
  143.                         reply=GetMsg(ReplyPort);
  144.                         res=(ULONG) msg.data;
  145.                 }
  146.                 else
  147.                 {
  148.                         // Give out this (or similiar) error message here:
  149.                         // "Stargate not found or fxPAINT not started"
  150.                 }
  151.  
  152.                 DeleteMsgPort(ReplyPort);
  153.         }
  154.  
  155.         return(res);
  156. }
  157.  
  158. // Get pointer to picture n`s fsb
  159. struct fsbitmap *get_fsb_in_stargate (long n)
  160. {
  161.         struct SGMessageExt msg;
  162.         struct Message *reply;
  163.         struct MsgPort *ReplyPort;
  164.         struct MsgPort *SGPort;
  165.         struct fsbitmap *res=NULL;
  166.  
  167.         if (ReplyPort=CreateMsgPort())
  168.         {
  169.                 Forbid();
  170.                 if (SGPort=FindPort("Stargate Airport"))
  171.                 {
  172.                         msg.msg.mn_Node.ln_Type = NT_MESSAGE;
  173.                         msg.msg.mn_Length       = sizeof(struct SGMessageExt);
  174.                         msg.msg.mn_ReplyPort    = ReplyPort;
  175.                         msg.type                = SG_GET_BITMAP;
  176.                         msg.data                = (ULONG) n;
  177.  
  178.                         PutMsg(SGPort, (struct Message *) &msg);
  179.                 }
  180.                 Permit();
  181.  
  182.                 if (SGPort)
  183.                 {
  184.                         Wait(1L << ReplyPort->mp_SigBit);
  185.                         reply=GetMsg(ReplyPort);
  186.                         res=(ULONG) msg.data;
  187.                 }
  188.                 else
  189.                 {
  190.                         // Give out this (or similiar) error message here:
  191.                         // "Stargate not found or fxPAINT not started"
  192.                 }
  193.  
  194.                 DeleteMsgPort(ReplyPort);
  195.         }
  196.  
  197.         return(res);
  198. }
  199.  
  200. /* EXAMPLE 1 */
  201.  
  202. void main(int argc, char *argv[])
  203. {
  204.         if (argc > 1)
  205.         {
  206.                 printf("Sending %s to fxPAINT ..\n",argv[1]);
  207.                 if (sendfile_to_stargate(argv[1]))
  208.                 {
  209.                         printf(".. sent!\n");
  210.                         exit(0);
  211.                 }
  212.                 else
  213.                 {
  214.                         printf("Stargate not found or fxPAINT not running ..\n");
  215.                         exit(5);
  216.                 }
  217.         }
  218.         else
  219.         {
  220.                 printf("Usage: StarGateExample [file]\n");
  221.                 exit(5);
  222.         }
  223. }
  224.  
  225. /* EXAMPLE 2 */
  226. /* void main(int argc, char *argv[])
  227. {
  228.         long num;
  229.         struct fsbitmap *fsb;
  230.         FILE *p_out;
  231.  
  232.         if (argc > 2)
  233.         {
  234.                 if (num = num_of_pics_in_stargate ())
  235.                 {
  236.                         printf("Pictures in memory: %ld\n",num);
  237.  
  238.                         if ((atol(argv[2])>=0) && (atol(argv[2])<num))
  239.                         {
  240.                                 if (fsb = get_fsb_in_stargate(atol(argv[2])))
  241.                                 {
  242.                                         if (p_out=fopen(argv[1],"wb"))
  243.                                         {
  244.                                                 fprintf (p_out,"P6\n%ld %ld\n255\n", fsb->width, fsb->height);
  245.                                                 fwrite  (fsb->location, fsb->width*fsb->height*3, 1, p_out);
  246.                                                 fclose  (p_out);
  247.                                         }
  248.                                 }
  249.                         }
  250.                 }
  251.                 else
  252.                 {
  253.                         printf("Stargate not found, no pictures available or fxPAINT not running ..\n");
  254.                         exit(5);
  255.                 }
  256.         }
  257.         else
  258.         {
  259.                 printf("Usage: StarGateExample [file] [num]\n");
  260.                 exit(5);
  261.         }
  262. } */
  263.